﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Tizer.Utilities
{
    public class Reflector
    {
        public static String GetPropertyName<T>(Expression<Func<T, object>> property)
        {
            UnaryExpression unaryExpression = property.Body as UnaryExpression;
            MemberExpression memberExpression =
                    (MemberExpression)(unaryExpression != null ? unaryExpression.Operand : property.Body);
            return memberExpression.Member.Name;
        }

        public static String GetMethodName<T>(Expression<Func<T, object>> method)
        {
            MethodCallExpression methodCall = method.Body as MethodCallExpression;
            if (methodCall == null)
            {
                throw new ArgumentException();
            }
            return methodCall.Method.Name;
        }

    }
}
